-- lazy.nvim 配置
return {
  {
    "nvim-neo-tree/neo-tree.nvim",
    -- branch = "v3.x",
    enabled = false,
    dependencies = {
      "nvim-lua/plenary.nvim",
      "nvim-tree/nvim-web-devicons", -- icon
      "MunifTanjim/nui.nvim", -- ui
    },
    config = function()
      require("neo-tree").setup {}

      --[[
      require("neo-tree").setup {
        -- 窗口配置
        window = {
          position = "left",
          width = 40,
          mapping_options = {
            noremap = true,
            nowait = true,
          },
          mappings = {
            -- 默认按键映射
            ["<space>"] = {
              "toggle_node",
              nowait = false,
            },
            ["<2-LeftMouse>"] = "open",
            ["<cr>"] = "open",
            ["<esc>"] = "cancel",
            ["P"] = { "toggle_preview", config = { use_float = true } },
            ["l"] = "open",
            ["h"] = "close_node",
            ["S"] = "open_split",
            ["s"] = "open_vsplit",
            ["t"] = "open_tabnew",
            ["w"] = "open_with_window_picker",
            ["C"] = "close_node",
            ["z"] = "close_all_nodes",
            ["a"] = {
              "add",
              config = {
                show_path = "none",
              },
            },
            ["A"] = "add_directory",
            ["d"] = "delete",
            ["r"] = "rename",
            ["y"] = "copy_to_clipboard",
            ["x"] = "cut_to_clipboard",
            ["p"] = "paste_from_clipboard",
            ["c"] = "copy",
            -- ["c"] = {
            --  "copy",
            --  config = {
            --    show_path = "none" -- "none", "relative", "absolute"
            --  }
            --}
            ["m"] = "move",
            ["q"] = "close_window",
            ["R"] = "refresh",
            ["?"] = "show_help",
            ["<"] = "prev_source",
            [">"] = "next_source",

            ["i"] = {
              "show_file_details",
              -- format strings of the timestamps shown for date created and last modified (see `:h os.date()`)
              -- both options accept a string or a function that takes in the date in seconds and returns a string to display
              -- config = {
              --   created_format = "%Y-%m-%d %I:%M %p",
              --   modified_format = "relative", -- equivalent to the line below
              --   modified_format = function(seconds) return require('neo-tree.utils').relative_date(seconds) end
              -- }
            },

            ["Y"] = function(state)
              local node = state.tree:get_node()
              local path = node:get_id()
              -- 复制绝对路径
              vim.fn.setreg(
                "+",
                vim.fn.fnamemodify(path, ":!cp --parents % /target/dir")
              )

              print("Copied absolute path: " .. path)
            end,
            ["X"] = function(state)
              local node = state.tree:get_node()
              local path = node:get_id()
              -- 复制相对路径（相对于当前工作目录）
              vim.fn.setreg("+", vim.fn.fnamemodify(path, ":."))
              print("Copied relative path: " .. path)
            end,
          },
        },

        -- 关闭 Neo-tree 时自动关闭最后一个窗口
        close_if_last_window = false,

        -- 启用弹出模式
        popup_border_style = "rounded",

        -- 启用 git 状态
        enable_git_status = true,

        -- 启用诊断
        enable_diagnostics = true,

        -- 默认源配置
        default_component_configs = {
          -- 容器配置
          container = {
            enable_character_fade = true,
          },

          -- 缩进配置
          indent = {
            indent_size = 2,
            padding = 1,
            with_markers = true,
            indent_marker = "│",
            last_indent_marker = "└",
            highlight = "NeoTreeIndentMarker",
            with_expanders = nil,
            expander_collapsed = "",
            expander_expanded = "",
            expander_highlight = "NeoTreeExpander",
          },

          -- 图标配置
          icon = {
            folder_closed = "",
            folder_open = "",
            folder_empty = "",
            default = "",
            highlight = "NeoTreeFileIcon",
          },

          -- 修改名称配置
          modified = {
            symbol = "[+]",
            highlight = "NeoTreeModified",
          },

          -- 名称配置
          name = {
            trailing_slash = false,
            use_git_status_colors = true,
            highlight = "NeoTreeFileName",
          },

          -- git 状态配置
          git_status = {
            symbols = {
              added = "✚",
              modified = "",
              deleted = "✖",
              renamed = "",
              untracked = "?",
              ignored = "",
              unstaged = "",
              staged = "",
              conflict = "",
            },
          },
        },

        -- 文件系统配置
        filesystem = {
          window = {
            mappings = {
              ["H"] = "toggle_hidden",
              ["/"] = "fuzzy_finder",
              ["D"] = "fuzzy_finder_directory",
              ["#"] = "fuzzy_sorter",
              ["f"] = "filter_on_submit",
              ["<C-f>"] = "clear_filter",
              ["[g"] = "prev_git_modified",
              ["]g"] = "next_git_modified",
              ["o"] = {
                "show_help",
                nowait = false,
                config = { title = "Order by", prefix_key = "o" },
              },
              ["oc"] = { "order_by_created", nowait = false },
              ["od"] = { "order_by_diagnostics", nowait = false },
              ["og"] = { "order_by_git_status", nowait = false },
              ["om"] = { "order_by_modified", nowait = false },
              ["on"] = { "order_by_name", nowait = false },
              ["os"] = { "order_by_size", nowait = false },
              ["ot"] = { "order_by_type", nowait = false },
            },
            fuzzy_finder_mappings = {
              ["<C-j>"] = "move_cursor_down",
              ["<C-k>"] = "move_cursor_up",
            },
          },

          -- 过滤配置
          filtered_items = {
            visible = false,
            hide_dotfiles = true,
            hide_gitignored = true,
            hide_hidden = true,
            hide_by_name = {
              "node_modules",
              ".git",
              "__pycache__",
              ".DS_Store",
              "thumbs.db",
            },
            hide_by_pattern = {
              "*.meta",
              "*/src/*/obj/*",
              "*/src/*/bin/*",
              "*/tmp/*",
            },
            always_show = {
              ".gitignore",
              ".env",
              ".env.local",
            },
            never_show = {
              ".DS_Store",
              "thumbs.db",
            },
          },

          -- 查找文件配置
          find_by_full_path_words = false,

          -- 分组配置
          group_empty_dirs = false,

          -- 使用 libuv 文件监视器
          use_libuv_file_watcher = true,

          -- 窗口配置
          bind_to_cwd = true,
          follow_current_file = {
            enabled = true,
            leave_dirs_open = false,
          },

          -- 悬停配置
          hijack_netrw_behavior = "open_default",
        },

        -- 缓冲区配置
        buffers = {
          show_unloaded = true,
          window = {
            mappings = {
              ["bd"] = "buffer_delete",
              ["<bs>"] = "navigate_up",
              ["."] = "set_root",
              ["o"] = {
                "show_help",
                nowait = false,
                config = { title = "Order by", prefix_key = "o" },
              },
              ["oc"] = { "order_by_created", nowait = false },
              ["od"] = { "order_by_diagnostics", nowait = false },
              ["om"] = { "order_by_modified", nowait = false },
              ["on"] = { "order_by_name", nowait = false },
              ["os"] = { "order_by_size", nowait = false },
              ["ot"] = { "order_by_type", nowait = false },
            },
          },
        },

        -- git 状态配置
        git_status = {
          window = {
            position = "float",
            mappings = {
              ["A"] = "git_add_all",
              ["gu"] = "git_unstage_file",
              ["ga"] = "git_add_file",
              ["gr"] = "git_revert_file",
              ["gc"] = "git_commit",
              ["gp"] = "git_push",
              ["gg"] = "git_commit_and_push",
              ["o"] = {
                "show_help",
                nowait = false,
                config = { title = "Order by", prefix_key = "o" },
              },
              ["oc"] = { "order_by_created", nowait = false },
              ["od"] = { "order_by_diagnostics", nowait = false },
              ["om"] = { "order_by_modified", nowait = false },
              ["on"] = { "order_by_name", nowait = false },
              ["os"] = { "order_by_size", nowait = false },
              ["ot"] = { "order_by_type", nowait = false },
            },
          },
        },

        -- 事件处理器
        event_handlers = {
          {
            event = "neo_tree_buffer_enter",
            handler = function()
              vim.opt_local.signcolumn = "auto"
            end,
          },
          {
            event = "file_opened",
            handler = function(file_path)
              -- 打开文件后自动关闭 neo-tree
              require("neo-tree").close_all()
            end,
          },
        },
      }
      ]]

      -- 全局按键映射
      vim.keymap.set(
        "n",
        "<leader>ee",
        "<cmd>Neotree toggle<cr>",
        { desc = "Toggle Neo-tree" }
      )
      vim.keymap.set(
        "n",
        "<leader>eo",
        "<cmd>Neotree focus<cr>",
        { desc = "Focus Neo-tree" }
      )
      vim.keymap.set(
        "n",
        "<leader>ebf",
        "<cmd>Neotree buffers focus<cr>",
        { desc = "Focus buffers" }
      )
      vim.keymap.set(
        "n",
        "<leader>egf",
        "<cmd>Neotree git_status focus<cr>",
        { desc = "Focus git status" }
      )

      -- 文件操作快捷键
      local map_opts = { noremap = true, silent = true }

      -- 在 normal 模式下快速打开文件树
      vim.keymap.set("n", "<C-n>", "<cmd>Neotree toggle<cr>", map_opts)

      -- -- 快速导航
      -- vim.keymap.set(
      --   "n",
      --   "<leader>1",
      --   "<cmd>Neotree focus filesystem left<cr>",
      --   map_opts
      -- )
      -- vim.keymap.set(
      --   "n",
      --   "<leader>2",
      --   "<cmd>Neotree focus buffers left<cr>",
      --   map_opts
      -- )
      -- vim.keymap.set(
      --   "n",
      --   "<leader>3",
      --   "<cmd>Neotree focus git_status left<cr>",
      --   map_opts
      -- )
    end,
  },
}
